package gek.uni.diplom.integrate.wizard.actions;

import gek.uni.diplom.integrate.wizard.NewTestDescFileWizard;

import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.m2m.atl.engine.vm.AtlLauncher;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.PlatformUI;

public class TestDescriptionCreationAction implements IObjectActionDelegate {

  private static final int SIZING_WIZARD_WIDTH = 500;
  private static final int SIZING_WIZARD_HEIGHT = 500;
  IWorkbenchPart part = null;
  ISelection selection = null;
  
  public TestDescriptionCreationAction() {
  }

  @Override
  public void setActivePart(IAction action, IWorkbenchPart targetPart) {
    this.part = targetPart;
  }

  @Override
  public void run(IAction action) {
//    try {
//      runAtlAutomatically();
//    } catch (Exception e) {
//      e.printStackTrace();
//    }
    INewWizard wizard = new NewTestDescFileWizard();
    wizard.init(PlatformUI.getWorkbench(), (IStructuredSelection) selection);
    
    Shell parentShell = part.getSite().getWorkbenchWindow().getShell();
    WizardDialog dialog = new WizardDialog(parentShell, wizard);
    dialog.create();
    
    Point defaultSize = dialog.getShell().getSize();
    dialog.getShell().setSize(
            Math.max(SIZING_WIZARD_WIDTH, defaultSize.x),
            Math.max(SIZING_WIZARD_HEIGHT, defaultSize.y));

    dialog.open();
  }

  @Override
  public void selectionChanged(IAction action, ISelection selection) {
    this.selection = selection;
  }
  
  public void runAtlAutomatically() throws Exception{
    ATLTransformation transformation = new ATLTransformation();
    transformation.main();
  }

}
